package Card;

import com.sun.org.apache.bcel.internal.generic.SWAP;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * Date: 2024-01-31
 * Time:22:40
 */
public class CardDemo {
    //public List<Card> CardHeap;
    public final String[] suit = {"♥","♦","♠","♣"};

    public List<Card> GenerateCard() {
        List<Card> cardList = new ArrayList<>();
        for(int i = 0 ; i <= 3;i++) {
            for(int j = 1;j <= 13;j++) {
                Card card = new Card(j,suit[i]);
                cardList.add(card);
            }
        }
        return cardList;
    }

    public static void display(List<Card> cardList) {
        for(int i = 0;i < cardList.size();i++) {
            System.out.print(cardList.get(i) + " ");
        }
        System.out.println();
    }

    //交换cardlist中i下标和index下标的数据
    private void swap(List<Card> cardList,int i,int index) {
        Card tmp = cardList.get(i);
        cardList.set(i,cardList.get(index));
        cardList.set(index,tmp);
    }

    //洗牌
    public void shuffle(List<Card> cardList) {
        Random random = new Random();
        for(int i = cardList.size()-1;i>0;i--) {
            int index = random.nextInt(i);
            swap(cardList,i,index);
        }
    }

    //发牌
    public void getCard(List<Card> cardList) {
        List<List<Card>> person = new ArrayList<>();
        List<Card> person1 = new ArrayList<>();
        List<Card> person2 = new ArrayList<>();
        List<Card> person3 = new ArrayList<>();
        person.add(person1);
        person.add(person2);
        person.add(person3);


        for(int i = 0;i<5;i++) {
            for(int j = 0;j < 3;j++) {
                Card card = cardList.remove(0);  //获得0下标处的牌，并将这张牌从牌堆里移除（取牌堆顶部的牌）
                person.get(j).add(card);
            }
        }
        System.out.println("第一个人拿到的牌为"+person1);
        System.out.println("第二个人拿到的牌为"+person2);
        System.out.println("第三个人拿到的牌为"+person3);
    }
}
